﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WuDada.Core.Post.Domain;
using WuDada.Core.Post.Persistence;
using NHibernate;

namespace WuDada.Core.Post.Service.Impl
{
    public class QuestionService : IQuestionService
    {
        public IQuestionDao QuestionDao { get; set; }

        /// <summary>
        /// 新增Question
        /// </summary>
        /// <param name="questionVO">被新增的Question</param>
        /// <returns>新增後的Question</returns>
        public QuestionVO CreateQuestion(QuestionVO questionVO)
        {
            questionVO = QuestionDao.CreateQuestion(questionVO);
            if (questionVO.SortNo == 0)
            {
                questionVO.SortNo = questionVO.QuestionId;
                questionVO = QuestionDao.UpdateQuestion(questionVO);
            }
            return questionVO;
        }

        /// <summary>
        /// 取得Question By QuestionId
        /// </summary>
        /// <param name="questionId">QuestionId</param>
        /// <returns>Question</returns>
        public QuestionVO GetQuestionById(int questionId)
        {
            return QuestionDao.GetQuestionById(questionId);
        }

        /// <summary>
        /// 刪除Question
        /// </summary>
        /// <param name="questionVO">被刪除的Question</param>
        public void DeleteQuestion(QuestionVO questionVO)
        {
            QuestionDao.DeleteQuestion(questionVO);
        }

        /// <summary>
        /// 更新Question
        /// </summary>
        /// <param name="questionVO">被更新的Question</param>
        /// <returns>更新後的Question</returns>
        public QuestionVO UpdateQuestion(QuestionVO questionVO)
        {
            return QuestionDao.UpdateQuestion(questionVO);
        }

        /// <summary>
        /// 取得Question清單
        /// </summary>
        /// <param name="conditions">搜尋條件</param>
        /// <returns>Question清單</returns>
        public IList<QuestionVO> GetQuestionList(IDictionary<string, string> conditions)
        {
            return QuestionDao.GetQuestionList(conditions);
        }

        /// <summary>
        /// 取得Question數量
        /// </summary>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public int GetQuestionCount(IDictionary<string, string> conditions)
        {
            return QuestionDao.GetQuestionCount(conditions);
        }
    }
}
